﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;

namespace EnterpriseFund.Common
{
    public class ImageResult : ActionResult
    {
        public ImageResult() { }

        public byte[] byteStream;

        public override void ExecuteResult(ControllerContext context)
        {
            context.HttpContext.Response.ContentType = "image/jpeg";
            context.HttpContext.Response.Cache.SetCacheability(HttpCacheability.Public);
            context.HttpContext.Response.BufferOutput = false;


            const int buffersize = 1024 * 32;
            byte[] buffer = new byte[buffersize];

            Stream stream = new MemoryStream(byteStream);
            int count = stream.Read(buffer, 0, buffersize);
            while (count > 0)
            {
                context.HttpContext.Response.OutputStream.Write(buffer, 0, count);
                count = stream.Read(buffer, 0, buffersize);
            }

        }
    }
}